/***************************************************************************
 * 
 * Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved
 * $Id$ 
 * 
 **************************************************************************/
 
 
 
/**
 * @file reader_helper.cpp
 * @author zengdelong(zengdelong@baidu.com)
 * @date 2012/03/24 20:52:45
 * @version $Revision$ 
 * @brief 
 */
#include "reader_helper.h"

int get_kv_key(FILE *fp, const char *key){
	bool has_key = false;
	char line[LINE_LEN];

	int num = -1;

	char *p;
	while(fgets(line, LINE_LEN, fp)){
		p = strstr(line, key);
		if (p == NULL){
			continue;
		}

		p = strchr(line,':');
		char tmp_str[LINE_LEN];
		memset(tmp_str, 0, LINE_LEN);
		strncpy(tmp_str, line, p-line);
		
		if (0 == strcmp(tmp_str, key)){
			num = atoi(p+1);
			has_key = true;
			break;
		}
	}

	if (has_key == true){
		return num;
	}else{
		return -1;
	}
}






















/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
